import apiClient from "../apiClient";

export interface Knowledge {
	id: number;
	title: string;
	content: string;
	url: string;
	createtime: number;
	updatetime: number;
}

export interface KnowledgeResponse {
	total: number;
	items: Knowledge[];
}

export interface ApiResponse<T> {
	status: number;
	message: string;
	time: string;
	data: T;
}

export interface KnowledgeListParams {
	page: number;
	limit: number;
	keyword?: string;
}

export enum KnowledgeApi {
	KnowledgeList = "/knowledge/index",
	KnowledgeInfo = "/knowledge/info",
}

const knowledgeList = (params: KnowledgeListParams) =>
	apiClient.get<ApiResponse<KnowledgeResponse>>({
		url: KnowledgeApi.KnowledgeList,
		params,
	});

const knowledgeInfo = (id: number) =>
	apiClient.get<ApiResponse<Knowledge>>({
		url: `${KnowledgeApi.KnowledgeInfo}/${id}`,
	});

export const knowledgeService = {
	knowledgeList,
	knowledgeInfo,
};
